home *** CD-ROM | disk | FTP | other *** search
- head 1.9;
- branch ;
- access ;
- symbols patch1:1.9 arc521:1.5;
- locks ; strict;
- comment @ * @;
-
-
- 1.9
- date 88.07.31.18.49.19; author hyc; state Exp;
- branches ;
- next 1.8;
-
- 1.8
- date 88.07.19.16.00.12; author hyc; state Exp;
- branches ;
- next 1.7;
-
- 1.7
- date 88.06.02.16.27.32; author hyc; state Exp;
- branches ;
- next 1.6;
-
- 1.6
- date 88.06.01.19.26.50; author hyc; state Exp;
- branches ;
- next 1.5;
-
- 1.5
- date 88.06.01.17.58.29; author hyc; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 88.06.01.15.40.40; author hyc; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.06.01.14.46.33; author hyc; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.04.11.18.01.16; author hyc; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.04.11.17.59.43; author hyc; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.9
- log
- @Initialize hdr size & length to zero before using 'em.
- @
- text
- @/*
- * $Header: arcio.c,v 1.8 88/07/19 16:00:12 hyc Locked $
- */
-
- /* ARC - Archive utility - ARCIO
-
- Version 2.50, created on 04/22/87 at 13:25:20
-
- (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
-
- By: Thom Henderson
-
- Description:
- This file contains the file I/O routines used to manipulate
- an archive.
-
- Language:
- Computer Innovations Optimizing C86
- */
- #include <stdio.h>
- #include "arc.h"
- #if MTS
- #include <ctype.h>
- #endif
-
- void abort();
- int strlen(), free();
-
- int
- readhdr(hdr, f) /* read a header from an archive */
- struct heads *hdr; /* storage for header */
- FILE *f; /* archive to read header from */
- {
- #if !MSDOS
- unsigned char dummy[28];
- int i;
- #endif
- char name[FNLEN]; /* filename buffer */
- int try = 0;/* retry counter */
- static int first = 1; /* true only on first read */
-
- if (!f) /* if archive didn't open */
- return 0; /* then pretend it's the end */
- if (feof(f)) /* if no more data */
- return 0; /* then signal end of archive */
-
- if (fgetc(f) != ARCMARK) { /* check archive validity */
- if (warn) {
- printf("An entry in %s has a bad header.", arcname);
- nerrs++;
- }
- while (!feof(f)) {
- try++;
- if (fgetc(f) == ARCMARK) {
- ungetc(hdrver = fgetc(f), f);
- if (!(hdrver & 0x80) && hdrver <= ARCVER)
- break;
- }
- }
-
- if (feof(f) && first)
- abort("%s is not an archive", arcname);
-
- if (changing && warn)
- abort("%s is corrupted -- changes disallowed", arcname);
-
- if (warn)
- printf(" %d bytes skipped.\n", try);
-
- if (feof(f))
- return 0;
- }
- hdrver = fgetc(f); /* get header version */
- if (hdrver & 0x80) /* sign bit? negative? */
- abort("Invalid header in archive %s", arcname);
- if (hdrver == 0)
- return 0; /* note our end of archive marker */
- if (hdrver > ARCVER) {
- fread(name, sizeof(char), FNLEN, f);
- #if MTS
- atoe(name, strlen(name));
- #endif
- printf("I don't know how to handle file %s in archive %s\n",
- name, arcname);
- printf("I think you need a newer version of ARC.\n");
- exit(1);
- }
- /* amount to read depends on header type */
-
- if (hdrver == 1) { /* old style is shorter */
- fread(hdr, sizeof(struct heads) - sizeof(long int), 1, f);
- hdrver = 2; /* convert header to new format */
- hdr->length = hdr->size; /* size is same when not
- * packed */
- } else
- #if MSDOS
- fread(hdr, sizeof(struct heads), 1, f);
- #else
- fread(dummy, 27, 1, f);
-
- for (i = 0; i < FNLEN; hdr->name[i] = dummy[i], i++);
- #if MTS
- (void) atoe(hdr->name, strlen(hdr->name));
- #endif
- for (i = 0, hdr->size=0; i<4; hdr->size<<=8, hdr->size += dummy[16-i], i++);
- hdr->date = (short) ((dummy[18] << 8) + dummy[17]);
- hdr->time = (short) ((dummy[20] << 8) + dummy[19]);
- hdr->crc = (short) ((dummy[22] << 8) + dummy[21]);
- for (i = 0, hdr->length=0; i<4; hdr->length<<=8, hdr->length += dummy[26-i], i++);
- #endif
-
- if (hdr->date > olddate
- || (hdr->date == olddate && hdr->time > oldtime)) {
- olddate = hdr->date;
- oldtime = hdr->time;
- }
- first = 0;
- return 1; /* we read something */
- }
-
- void
- put_int(number, f) /* write a 2 byte integer */
- short number;
- FILE *f;
- {
- fputc((char) (number & 255), f);
- fputc((char) (number >> 8), f);
- }
-
- void
- put_long(number, f) /* write a 4 byte integer */
- long number;
- FILE *f;
- {
- put_int((short) (number & 0xFFFF), f);
- put_int((short) (number >> 16), f);
- }
-
- void
- writehdr(hdr, f) /* write a header to an archive */
- struct heads *hdr; /* header to write */
- FILE *f; /* archive to write to */
- {
- fputc(ARCMARK, f); /* write out the mark of ARC */
- fputc(hdrver, f); /* write out the header version */
- if (!hdrver) /* if that's the end */
- return; /* then write no more */
- #if MSDOS
- fwrite(hdr, sizeof(struct heads), 1, f);
- #else
- /* byte/word ordering hassles... */
- #if MTS
- etoa(hdr->name, strlen(hdr->name));
- #endif
- fwrite(hdr->name, 1, FNLEN, f);
- put_long(hdr->size, f);
- put_int(hdr->date, f);
- put_int(hdr->time, f);
- put_int(hdr->crc, f);
- put_long(hdr->length, f);
- #endif
-
- /* note the newest file for updating the archive timestamp */
-
- if (hdr->date > arcdate
- || (hdr->date == arcdate && hdr->time > arctime)) {
- arcdate = hdr->date;
- arctime = hdr->time;
- }
- }
-
- void
- putc_tst(c, t) /* put a character, with tests */
- char c; /* character to output */
- FILE *t; /* file to write to */
- {
- c &= 0xff;
- if (t) {
- #if UNIX
- fputc(c, t);
- if (ferror(t))
- abort("Write failed");
- #else
- if (fputc(c, t) == EOF)
- abort("Write fail (disk full?)");
- #endif
- }
- }
-
- /*
- * NOTE: The filecopy() function is used to move large numbers of bytes from
- * one file to another. This particular version has been modified to improve
- * performance in Computer Innovations C86 version 2.3 in the small memory
- * model. It may not work as expected with other compilers or libraries, or
- * indeed with different versions of the CI-C86 compiler and library, or with
- * the same version in a different memory model.
- *
- * The following is a functional equivalent to the filecopy() routine that
- * should work properly on any system using any compiler, albeit at the cost
- * of reduced performance:
- *
- * filecopy(f,t,size)
- * FILE *f, *t; long size;
- * {
- * while(size--)
- * putc_tst(fgetc(f),t);
- * }
- */
- #if MSDOS
- #include <fileio2.h>
-
- filecopy(f, t, size) /* bulk file copier */
- FILE *f, *t; /* files from and to */
- long size; /* bytes to copy */
- {
- char *buf; /* buffer pointer */
- char *alloc();/* buffer allocator */
- unsigned int bufl; /* buffer length */
- unsigned int coreleft(); /* space available reporter */
- unsigned int cpy; /* bytes being copied */
- long floc, tloc, fseek(); /* file pointers, setter */
- struct regval reg; /* registers for DOS calls */
-
- if ((bufl = coreleft()) < 1000) /* see how much space we have */
- abort("Out of memory");
- bufl -= 1000; /* fudge factor for overhead */
- if (bufl > 60000)
- bufl = 60000; /* avoid choking alloc() */
- if (bufl > size)
- bufl = size; /* avoid wasting space */
- buf = alloc(bufl); /* allocate our buffer */
-
- floc = fseek(f, 0L, 1); /* reset I/O system */
- tloc = fseek(t, 0L, 1);
-
- segread(®.si); /* set segment registers for DOS */
-
- while (size > 0) { /* while more to copy */
- reg.ax = 0x3F00;/* read from handle */
- reg.bx = filehand(f);
- reg.cx = bufl < size ? bufl : size; /* amount to read */
- reg.dx = buf;
- if (sysint21(®, ®) & 1)
- abort("Read fail");
-
- cpy = reg.ax; /* amount actually read */
- reg.ax = 0x4000;/* write to handle */
- reg.bx = filehand(t);
- reg.cx = cpy;
- reg.dx = buf;
- sysint21(®, ®);
-
- if (reg.ax != cpy)
- abort("Write fail (disk full?)");
-
- size -= (long) cpy;
- }
-
- free(buf); /* all done with buffer */
- }
- #else
-
- void
- filecopy(f, t, size) /* bulk file copier */
- FILE *f, *t; /* files from and to */
- long size; /* bytes to copy */
- {
- char *buf; /* buffer pointer */
- char *malloc(); /* buffer allocator */
- unsigned int bufl; /* buffer length */
- unsigned int cpy; /* bytes being copied */
-
- bufl = 32760;
- if (bufl > size)
- bufl = size; /* don't waste space */
-
- buf = malloc(bufl);
-
- while (size > 0) {
- cpy = fread(buf, sizeof(char),
- bufl < size ? bufl : (unsigned short) size, f);
- if (fwrite(buf, sizeof(char), cpy, t) != cpy)
- abort("Write fail (no space?)");
- size -= cpy;
- }
-
- free(buf);
- }
- #endif
- @
-
-
- 1.8
- log
- @Fixes from John Gilmore, message date Mon, 4 Jul 88 03:02:43 PDT
- @
- text
- @d2 1
- a2 1
- * $Header: arcio.c,v 1.7 88/06/02 16:27:32 hyc Locked $
- d105 1
- a105 1
- for (i = 0; i<4; hdr->size<<=8, hdr->size += dummy[16-i], i++);
- d109 1
- a109 1
- for (i = 0; i<4; hdr->length<<=8, hdr->length += dummy[26-i], i++);
- @
-
-
- 1.7
- log
- @Minor fixes & speedups
- @
- text
- @d2 1
- a2 1
- * $Header: arcio.c,v 1.6 88/06/01 19:26:50 hyc Locked $
- d56 1
- a56 1
- if (hdrver >= 0 && hdrver <= ARCVER)
- d74 1
- a74 1
- if (hdrver < 0)
- d178 1
- a178 1
- if (t)
- d181 2
- d187 1
- @
-
-
- 1.6
- log
- @Changed compilation conditionals
- @
- text
- @d2 1
- a2 1
- * $Header: arcio.c,v 1.5 88/06/01 17:58:29 hyc Locked $
- d126 2
- a127 2
- fputc(number & 255, f);
- fputc(number >> 8, f); /* FIX? cast to (char) ? */
- d135 2
- a136 2
- put_int(number & 0xFFFF, f);
- put_int(number >> 16, f); /* FIX? cat to (short) ? */
- d277 2
- a278 2
- /* FIX? cast size to (unsigned int)? */
- cpy = fread(buf, sizeof(char), bufl < size ? bufl : size, f);
- @
-
-
- 1.5
- log
- @Merge ARC 5.21 changes
- @
- text
- @d2 1
- a2 1
- * $Header: arcio.c,v 1.4 88/06/01 15:40:40 hyc Locked $
- d22 1
- a22 1
- #ifdef MTS
- d34 1
- a34 1
- #ifndef MSDOS
- d80 1
- a80 1
- #ifdef MTS
- d96 1
- a96 1
- #ifdef MSDOS
- d102 1
- a102 1
- #ifdef MTS
- d148 1
- a148 1
- #ifdef MSDOS
- d152 1
- a152 1
- #ifdef MTS
- d179 1
- a179 1
- #ifdef BSD
- d206 1
- a206 1
- #ifdef MSDOS
- @
-
-
- 1.4
- log
- @Merge Atari ST code
- @
- text
- @d2 1
- a2 1
- * $Header: arcio.c,v 1.3 88/06/01 14:46:33 hyc Locked $
- d5 15
- a19 14
- /*
- * ARC - Archive utility - ARCIO
- *
- * Version 2.49, created on 07/25/86 at 16:44:23
- *
- * (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
- *
- * By: Thom Henderson
- *
- * Description: This file contains the file I/O routines used to manipulate an
- * archive.
- *
- * Language: Computer Innovations Optimizing C86
- */
- d63 3
- @
-
-
- 1.3
- log
- @Fixed declarations
- @
- text
- @d2 1
- a2 1
- * $Header: arcio.c,v 1.5 88/04/19 01:39:46 hyc Exp $
- d101 1
- a101 2
- hdr->size = (long) ((dummy[16] << 24) + (dummy[15] << 16) + (dummy[14] << 8)
- + dummy[13]);
- d105 1
- a105 2
- hdr->length = (long) ((dummy[26] << 24) + (dummy[25] << 16)
- + (dummy[24] << 8) + dummy[23]);
- d123 1
- a123 1
- fputc(number >> 8, f);
- d132 1
- a132 1
- put_int(number >> 16, f);
- d173 1
- d266 1
- a266 1
- bufl = 60000;
- d273 1
- @
-
-
- 1.2
- log
- @added support for squashing. (changed max hdrver from 8 to 9)
- @
- text
- @d2 1
- a2 20
- * $Log: arcio.c,v $
- * Revision 1.1 88/04/11 17:59:43 hyc
- * Initial revision
- *
- * Revision 1.3 87/12/19 04:25:24 hyc
- * As before, different location tho.
- *
- * Revision 1.2 87/12/19 04:23:21 hyc
- * Fix problem caused by indent(?) screwing up line boundaries...
- *
- * Revision 1.1 87/12/19 04:21:23 hyc
- * Initial revision
- *
- * Revision 1.4 87/08/13 17:03:24 hyc
- * Run thru the indent program...
- * Revision 1.3 87/07/21 11:41:29 hyc *** empty
- * log message ***
- *
- * Revision 1.2 87/07/21 08:19:45 hyc *** empty log message ***
- *
- d21 3
- d25 4
- a28 1
- INT
- d35 1
- a35 1
- INT i, j, k;
- d37 3
- a39 3
- char name[13]; /* filename buffer */
- INT try = 0;/* retry counter */
- static INT first = 1; /* true only on first read */
- d46 1
- a46 1
- if (fgetc(f) != 26) { /* check archive validity */
- d53 1
- a53 1
- if (fgetc(f) == 26) {
- d55 1
- a55 1
- if (hdrver >= 0 && hdrver <= 9)
- d74 2
- a75 2
- if (hdrver > 9) {
- fread(name, sizeof(char), 13, f);
- d97 1
- a97 1
- for (i = 0; i < 13; hdr->name[i] = dummy[i], i++);
- d101 1
- a101 1
- hdr->size = (LONG) ((dummy[16] << 24) + (dummy[15] << 16) + (dummy[14] << 8)
- d106 1
- a106 1
- hdr->length = (LONG) ((dummy[26] << 24) + (dummy[25] << 16)
- d119 1
- d121 1
- a121 1
- INT number;
- d128 1
- d130 1
- a130 1
- LONG number;
- d137 1
- a137 1
- INT
- d142 1
- a142 1
- fputc(26, f); /* write out the mark of ARC */
- d153 1
- a153 1
- fwrite(hdr->name, 1, 13, f);
- d170 1
- a170 1
- INT
- d257 1
- d260 1
- a260 1
- LONG size; /* bytes to copy */
- a265 3
- #ifdef MTS
- #define MTEXT 0x0010
- #endif
- a274 4
- #ifdef MTS
- if ((f->_fmode & MTEXT) && !image)
- etoa(buf, cpy);
- #endif
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d3 3
- d68 1
- a68 1
- if (hdrver >= 0 && hdrver <= 8)
- d87 1
- a87 1
- if (hdrver > 8) {
- d102 1
- a102 1
- hdr->length = hdr->size; /* size is same when not *
- @
-